Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong behavior when inserting rows into crossRef table with auto increment primary key column. #1676

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

WebsourceCz
Copy link

When inserting rows into crossRef table with auto increment primary key column defined at other than first position in table schema, then auto increment value is set to first defined primary key column instead of the correct one.

…ey column defined at other than first position in table schema, then auto increment value is set to first defined primary key column instead of the correct one.
@dereuromark
Copy link
Contributor

Can you add a test case for this please?

@dereuromark
Copy link
Contributor

ping @WebsourceCz

if ($table->isAllowPkInsert()) {
$script .= "
if (\$pk !== null) {
\$this->set" . $column->getPhpName() . "(\$pk);
\$this->set" . $col->getPhpName() . "(\$pk);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep the $column variable, or is there a conflict?

@dereuromark
Copy link
Contributor

Maybe you can provide as an example or alike we can add into the tests manually
Without that we cannot merge this I am afraid.

@WebsourceCz
Copy link
Author

WebsourceCz commented Apr 7, 2022

Imagine you have table for M:N relation of another two tables and you need to work with relation rows using autoincrement id. So xml schema of this table is for example:

<table name="page_page_group" isCrossRef="true">
<column name="page_id" type="integer" primaryKey="true" required="true" />
<column name="page_group_id" type="integer" primaryKey="true" required="true" />
<column name="id" type="integer" primaryKey="true" autoIncrement="true" required="true" />
<column name="priority" type="integer" required="true" defaultValue="0" />
<foreign-key foreignTable="page" name="page_page_group_FK_1" onDelete="cascade" onUpdate="cascade">
<reference local="page_id" foreign="id" />
</foreign-key>
<foreign-key foreignTable="page_group" name="page_page_group_FK_2" onDelete="cascade" onUpdate="cascade">
<reference local="page_group_id" foreign="id" />
</foreign-key>
</table>

When new row is inserted by Propel, old code found page_id as first primary key and set new auto increment id value returned from database to page_id column instead of id column. I know that I can set id as first column in the table, but I think, that when I tried it, there was some problem with auto creating of generated object and query methods for cross relation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants